package com.pb.camera.more;

import com.pb.camera.R;
import com.pb.camera.adapter.SettingFragmentAdapter;
import com.pb.camera.more.detail.BaseSetFragment;
import com.pb.camera.more.detail.DeviceSetFragment;
import com.pb.camera.more.detail.MoveDetectSetFragment;
import com.pb.camera.more.detail.ShowSetFragment;
import com.pb.camera.view.TabPageIndicator;
import com.pb.camera.work.IOTCInit;
import com.pb.camera.work.ReceiveTask;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MoreActivity extends FragmentActivity implements ViewPager.OnPageChangeListener {
	protected static final String TAG = "MoreActivity";
	private TabPageIndicator mTabPageIndicator; 
	private ViewPager mViewPager;
	private SettingFragmentAdapter mAdapter;
	private ReceiveTask mReceiveTask;
	private List<BaseSetFragment> mListFragment;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		mReceiveTask = ReceiveTask.getDefault();
		mReceiveTask.startReceiveTask(0);

		setContentView(R.layout.activity_more);
		mTabPageIndicator = (TabPageIndicator) findViewById(R.id.indicator_setPager);
		mViewPager = (ViewPager) findViewById(R.id.pager_setFragment);
		mAdapter = new SettingFragmentAdapter(getSupportFragmentManager(), this);
		mListFragment = new ArrayList<BaseSetFragment>();
		mListFragment.add(new ShowSetFragment());
		mListFragment.add(new DeviceSetFragment());
		mListFragment.add(new MoveDetectSetFragment());
		mAdapter.setListFragment(mListFragment);
		mViewPager.setOffscreenPageLimit(mListFragment.size());
		mViewPager.setAdapter(mAdapter);
		mTabPageIndicator.setViewPager(mViewPager);
		mTabPageIndicator.setOnPageChangeListener(this);
		findViewById(R.id.lv_title)
				.setBackgroundColor(getResources().getColor(R.color.title_background1));
		((TextView)findViewById(R.id.tv_title)).setText(R.string.more);
	}

	public ReceiveTask getReceiveTask() {
		return mReceiveTask;
	}

	public void finishActivity(View v){
		finish();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}

	@Override
	public void onPageSelected(int position) {
		 mListFragment.get(position).initData();
		 mListFragment.get(position).setIsIniting(true);
	}
	@Override
	public void onPageScrollStateChanged(int state) {}
}
